<?php
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
set_html('title','商户列表');
if($_RQ['op']=='list'){
	if($_RQ['cateid']){
		$_SESSION['mcateid']=$_RQ['cateid'];
		
	}
	$params=array('uniacid'=>$_SESSION['uniacid'],'cateid'=>$_SESSION['mcateid']);
	
	if($_RQ['postdata']){
		$postdata=get_postdata();
	}
	$orderby='id asc';
	if($postdata['key']=='time'){
		$orderby='jointime desc';
		
	}
	if(substr($postdata['key'], 0, 1)=='c'){
		$params['cateid']=substr($postdata['key'], 1, strlen($postdata['key'])-1);
		}
	if(trim($postdata['keyword'])){
		$params['merchname like']='%'.trim($postdata['keyword']).'%';
		$return['params']['keyword']=trim($postdata['keyword']);
	}
	//$return['list']=pdo_getall('jy_merch_category',array('uniacid'=>$_SESSION['uniacid']),'','','displayorder desc');
	$pindex = max(1, intval($_SESSION['page']));
	$psize = 15;
	$total='';
	$return['cate']=pdo_getslice('jy_merch_category',$params1,array($pindex,$psize),$total,$fields,'','id desc');
	//$orderby='id desc';
	$return['list']=pdo_getslice('jy_merch_user',$params,array($pindex,$psize),$total,$fields,'',$orderby);
	
	foreach($return['list'] as $k=>&$v){
		$v['catename']=pdo_getcolumn('jy_merch_category',array('id'=>$v['cateid']),'catename');		
		//$v['lat_lng']=json_decode($v['lat_lng'],true);
		$v['juli']=cfc('tools')->getdistance($postdata['lat_lng']['lng'],$postdata['lat_lng']['lat'],$v['lng'],$v['lat']);
		
		if($postdata['key']=='500'){
			if($v['juli']>'500'){
				unset($return['list'][$k]);
			}
		}
		if($postdata['key']=='1000'){
			if($v['juli']>'1000'){
				unset($return['list'][$k]);
			}
		}
		if($postdata['key']=='2000'){
			if($v['juli']>'2000'){
				unset($return['list'][$k]);
			}
		}
		if($postdata['key']=='5000'){
			if($v['juli']>'5000'){
				unset($return['list'][$k]);
			}
		}
		if($postdata['key']=='more'){
			if($v['juli']<'5000'){
				unset($return['list'][$k]);
			}
		}
		$v['juli']=intval($v['juli']/1000);
	}
	//默认按距离排序
	paixu($return['list'],'juli','asc');
	if($postdata['key']=='juli'){
		paixu($return['list'],'juli','asc');
	}
	$return['params']=array();	
	exi($return);
	
}

?>